package chapter06;

public class stair_1 {
    public static void main(String[] args) {
        stair_1 stair_1 = new stair_1();

        System.out.println(stair_1.climbStairs(3));
        System.out.println(stair_1.guihau(3));


    }
    //动态规划求解
    public  int guihau(int n){
        int[] dp=new int[n+1];
        //dp[1]=0;
        if(n==1){
            return 1;
        }
        dp[1]=1;
        dp[2]=2;
        for (int i = 3; i <=n; i++) {
            dp[i]=dp[i-1]+dp[i-2];

        }
        return dp[n];
    }

    public int climbStairs(int n) {
        int p=0;
        int q=0;
        int r=1;
        for (int i = 1; i <= n; i++) {
            p=q;
            q=r;
            r=p+q;
        }
        return r;

    }
}
